package loadgen;

import java.io.File;
import java.io.FileWriter;
import java.io.IOException;
import java.util.logging.Level;
import java.util.logging.Logger;

public class DiskStresser {

	Logger logger = Logger.getLogger(DiskStresser.class.getCanonicalName());
	
	/**
	 * @param args
	 */
	public static void main(String[] args) {
		new DiskStresser().generateLoad(30000);
	}
	
	/**
	 * 
	 * @param timeout The time in milliseconds to keep disk busy.
	 */
	public void generateLoad(long timeout)
	{
		long startTime = System.currentTimeMillis();
		while(System.currentTimeMillis() - startTime < timeout)
		{
			try 
			{			
				File f = new File("test.txt");
				if(f.exists())
				{
					f.delete();
				}
				f.createNewFile();
				FileWriter writer = new FileWriter(f);
				writer.append("a");
				writer.close();
				
			} catch (IOException e) {
				logger.log(Level.SEVERE, "Error during disk load generation: ", e);
			}
		}
	}

}
